﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication2.Baga
{
    public partial class Longer : System.Web.UI.Page
    {
        private Sqlserver sqlserver = new Sqlserver();
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Button1_Click(object sender, EventArgs e)
        {


            string sql = "select*from studentinfo where stu_name=@name and password=@paw";

            SqlParameter[] para ={
              new SqlParameter("@name",TextBox1.Text),
              new SqlParameter("@paw",TextBox2.Text)
        };


            DataTable table= sqlserver.Get(sql, para);
            if (table.Rows.Count > 0)
            {
                Session["name"] = TextBox1.Text;
                Response.Redirect("sessend.aspx");
            }
            else {
                Literal1.Text = "登入失败";
            }

            






            //    string connet = "server=LAPTOP-8HS8J7NL;uid=sa;pwd=2287431003a;database=Student_db";

            //    SqlConnection com = new SqlConnection(connet);

            //    com.Open();

            //    string name = TextBox1.Text;
            //    string pwd = TextBox2.Text;

            //    string sql = "select*from StudentInfo where stu_name=@name and password=@pwd";

            //    SqlParameter[] parameters ={
            //    new SqlParameter("@name",name),
            //    new SqlParameter("@pwd",pwd)
            //    };

            //    SqlCommand cmd = new SqlCommand(sql, com);
            //    cmd.Parameters.AddRange(parameters);


            //    SqlDataReader reader = cmd.ExecuteReader();
            //    //reader.Read();
            //    //cmd.ExecuteScalar();

            //    if (reader.Read())
            //    {
            //        Session["name"] = name;
            //        Response.Redirect("sessend.aspx");
            //    }
            //    else
            //    {
            //        Response.Redirect("Longer.aspx");
            //    }

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
           
            Response.Redirect("resgin.aspx");
        }





    }
}